//4,4,0,0,3,3
// 前两位m, n  m行, n列
// 使用bfs, 使用一个数组, 进行逐层传播的记录
// 同时要定义四个方向的数组
// 还需要计数, 每走完一轮, 判断下是否已经完成

const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let m, n; // m行, n列
let point1 = [];
let point2 = [];
rl.on("line", (line)=>{
    if(m === undefined) {
        const [a, b, c, d, e, f] = line.trim().split(",").map(Number)
        m = a
        n = b
        point1 = [c, d]
        point2 = [e, f]

        console.log(getResult(m, n, point1, point2))
        // clear
        m = n = undefined
        point1.length = 0
        point2.length = 0
    }

})


function getResult(m, n, point1, point2) {
    let arr = new Array(m).fill(null).map(_ => new Array(n).fill(0) )
    arr[point1[0]][point1[1]] = 1
    arr[point2[0]][point2[1]] = 1

    let pq = [point1, point2]
    let time = 0
    //let count = m * n - 2
    while(pq.length) {
        let length = pq.length;
        while(length) {
           const [x, y] = pq.shift()
            const direction = [
                [1, 0],
                [-1, 0],
                [0, 1],
                [0, -1],
            ]
            for (const [addx, addy] of direction) {
                let newX = x + addx
                let newY = y + addy
                if(newX>= 0 && newX < m && newY>= 0 && newY < n && arr[newX][newY] === 0) {
                    arr[newX][newY] = 1
                    pq.push([newX, newY])
                }
            }
            length--
        }
        time++
    }
    return time - 1
}